package dn.easy.common.core;

import android.app.Application;
import android.content.Context;
import android.widget.Toast;
import com.alibaba.android.arouter.launcher.ARouter;
import com.jess.arms.base.delegate.AppLifecycles;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import butterknife.ButterKnife;
import dn.easy.common.BuildConfig;
import dn.easy.common.commonutils.LogUtils;
import timber.log.Timber;

public class AppLifecyclesImpl implements AppLifecycles {

    public static Context mContext;

    @Override
    public void attachBaseContext(Context base) {
    }

    @Override
    public void onCreate(Application application) {
        mContext = application;
        if (BuildConfig.LOG_DEBUG) {//Timber日志打印
            Timber.plant(new Timber.DebugTree());
            ButterKnife.setDebug(true);
            ARouter.openLog();     // 打印日志
            ARouter.openDebug();   // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
//            RetrofitUrlManager.getInstance().setDebug(true);
        }
        LogUtils.logInit(true);

        ARouter.init(application); // 尽可能早,推荐在Application中初始化
        ZXingLibrary.initDisplayOpinion(application);
    }

    @Override
    public void onTerminate(Application application) {
    }

    /**
     * 短时间显示Toast
     *
     * @param message
     */
    public static void showShort(CharSequence message) {
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
    }


    /**
     * 短时间显示Toast
     *
     * @param strResId
     */
    public static void showShort(int strResId) {
        Toast.makeText(mContext, mContext.getResources().getText(strResId), Toast.LENGTH_SHORT).show();
    }

    /**
     * 长时间显示Toast
     *
     * @param message
     */
    public static void showLong(CharSequence message) {
        Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
    }

    /**
     * 长时间显示Toast
     *
     * @param strResId
     */
    public static void showLong(int strResId) {
        Toast.makeText(mContext, mContext.getResources().getText(strResId), Toast.LENGTH_LONG).show();
    }

}
